﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace YouTube
{
	/// <summary>
	/// Interaction logic for VideoItem.xaml
	/// </summary>
	public partial class VideoItem : UserControl
	{
		public VideoItem()
		{
			InitializeComponent();
		}

		protected override void OnMouseEnter(MouseEventArgs e)
		{
			base.OnMouseEnter(e);

			Uri previewFileUri = ((YouTubeVideo)DataContext).PreviewFileUri;
			if(previewFileUri != null)
			{
				mediaElement.Source = previewFileUri;
				mediaElement.Play();
			}
			else
				noVideoLinkText.Visibility = Visibility.Visible;

			mediaElementBorder.Visibility = Visibility.Visible;
		}

		protected override void OnMouseLeave(MouseEventArgs e)
		{
			base.OnMouseLeave(e);

			mediaElement.Close();
			mediaElement.Source = null;
			mediaElementBorder.Visibility = Visibility.Collapsed;
			noVideoLinkText.Visibility = Visibility.Collapsed;
		}
	}
}
